package cn.tedu.csmallproductzxj.controller;

import cn.tedu.csmallproductzxj.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmallproductzxj.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmallproductzxj.pojo.dto.AttributeTemplateAddNewDTO;
import cn.tedu.csmallproductzxj.pojo.dto.AttributeTemplateUpdateDTO;
import cn.tedu.csmallproductzxj.pojo.vo.AttributeTemplateStandardVO;
import cn.tedu.csmallproductzxj.service.IAttributeTemplateService;
import cn.tedu.csmallproductzxj.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/attributeTemplates")
@Api(tags="03.属性模板")
@Validated
public class AttributeTemplateController {

    @Autowired
    private IAttributeTemplateService attributeTemplateService;

    @PostMapping("/add-new")
    @ApiOperation("添加属性模板")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew( @Valid AttributeTemplateAddNewDTO attributeTemplateAddNewDTO){
        attributeTemplateService.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询属性模板详情")
    @ApiOperationSupport(order = 200)
    public JsonResult getStandardById(@Range(min = 1, message = "获取详情失败，ID值无效！")
                                          @PathVariable Long id){
        AttributeTemplateStandardVO queryResult=attributeTemplateService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @PostMapping("//{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除属性模板详情")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteAttributeTemplateMapperById(@Range(min = 1, message = "获取详情失败，ID值无效！")
                                      @PathVariable Long id){
        attributeTemplateService.deleteAttributeTemplateMapperById(id);
        return JsonResult.ok();
    }

    @PostMapping("{id:[0-9]+}/update")
    @ApiOperation("修改属性模板详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "相册ID", required = true, dataType = "long"),
    })
    public JsonResult updateInfoById(@Range(min = 1, message = "修改相册详情失败，ID值无效！")
                                     @PathVariable Long id, @Valid AttributeTemplateUpdateDTO attributeTemplateUpdateDTO) {
        attributeTemplateService.updateInfoById(id,attributeTemplateUpdateDTO);
        return JsonResult.ok();

    }

}
